package com.harmonk.firstscene.db.repository

import com.harmonk.firstscene.db.dao.TrafficEventDao
import com.harmonk.firstscene.db.dao.VehicleDao
import com.harmonk.firstscene.db.dao.PersonDao
import com.harmonk.firstscene.db.dao.EventNoteDao
import com.harmonk.firstscene.db.entity.TrafficEvent
import com.harmonk.firstscene.db.entity.Vehicle
import com.harmonk.firstscene.db.entity.Person
import com.harmonk.firstscene.db.entity.EventNote
import com.harmonk.firstscene.db.entity.EventWithAll
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.withContext

class TrafficEventRepository(
    private val trafficEventDao: TrafficEventDao,
) {
    fun getAllTrafficEvents(): Flow<List<TrafficEvent>> = trafficEventDao.getAllTrafficEvents()
    
    suspend fun insertTrafficEvent(trafficEvent: TrafficEvent): Long {
        val id = withContext(Dispatchers.IO) {
            trafficEventDao.insertTrafficEvent(trafficEvent)
        }
        return id
    }
    
    suspend fun updateTrafficEvent(trafficEvent: TrafficEvent) {
        trafficEventDao.updateTrafficEvent(trafficEvent)
    }
    
    suspend fun deleteTrafficEvent(trafficEvent: TrafficEvent) {
        trafficEventDao.deleteTrafficEvent(trafficEvent)
    }

    fun getEventById(eventId: Long): Flow<TrafficEvent> =
        trafficEventDao.getTrafficEvent(eventId)
}